package com.pesking.core.sqlparser.processor;

import java.util.Arrays;
import java.util.List;

import com.pesking.core.parameter.Parameter;
import com.pesking.core.sqlparser.parameter.SqlParameter;
import com.pesking.core.sqlparser.parameter.SqlParameterProcessor;
import com.pesking.core.thread.ThreadManage;

public class RequestURLParameterSqlHandler extends SqlParameterProcessor {

	@Override
	public String getTitle() {
		return "请求URL参数";
	}

	@Override
	public String getDescription() {
		return this.getTitle() + " 用请求URL赋值";
	}

	@Override
	public void handle(StringBuilder sbSQL, Parameter parameter, List<SqlParameter> processors,SqlParameter sqlParameter) {
		String url = ThreadManage.getCurrentRequest().getRequestURI();
		String cp = ThreadManage.getCurrentRequest().getContextPath();
		if (url.indexOf(cp) == 0) {
			url = url.substring(cp.length());
			sbSQL.append("'@").append(url).append("'");
		}
		else {
			sbSQL.append("'").append(url).append("'");
		}
	}

	@Override
	public List<String> getSqlParameterType() {
		return Arrays.asList(new String []{"REQUEST_URL"});
	}

}
